﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace baseSet.DAL
{
    public class readDataTabelColumn
    {

        //返回一个数据库表和视图
        public static SqlDataReader readTableList()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = dataConn.connOpen();
            cmd.CommandType = CommandType.Text;
            string selectStr = "select name from sysobjects   where xtype='U' or xtype='V'  order by xtype,name ";
            cmd.CommandText = selectStr;
            return cmd.ExecuteReader();
        }


        //返回一个数据库表和视图中的列名和数据类型
        public static SqlDataReader readTableByfieldList(string tableNames)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = dataConn.connOpen();
            cmd.CommandType = CommandType.Text;
            string selectStr = "select name,type_name(system_type_id) as columnType from sys.columns where object_id=object_id('"+tableNames+"') ";
            cmd.CommandText = selectStr;
            return cmd.ExecuteReader();
        }
    }
}
